﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using LibCommon;
using RTCCore;

namespace LibRTC.Core.MessageMap.WatcherEvent
{
    public class WatcherHandler : SimpleMessageHandler
    {
        private static ILogger LOGGER = LoggerFactory.GetLogger("WatcherEventHandler", null);

        public WatcherHandler() {
            _rtcEvent = RTC_EVENT.RTCE_WATCHER;
            _name = "WatcherEventHandler";
        }

        public override void Process(RTC_EVENT rtcEventType, object rtcEvent)
        {
            Debug.Assert(RTC_EVENT.RTCE_WATCHER == rtcEventType);
            Debug.Assert(null != rtcEvent);
            Debug.Assert(rtcEvent is IRTCWatcherEvent2);

            IRTCWatcherEvent2 watcherEvent2 = rtcEvent as IRTCWatcherEvent2;
            Debug.Assert(null != watcherEvent2);

            IRTCWatcher2 watcher2 = (IRTCWatcher2)watcherEvent2.Watcher;
            
            LOGGER.LogDebug(""+_rtcEvent+" From : "+watcher2.PresentityURI);

            if(RTC_WATCHER_EVENT_TYPE.RTCWET_WATCHER_OFFERING == watcherEvent2.EventType) {
                // we allow all of them now
                watcher2.State = RTC_WATCHER_STATE.RTCWS_ALLOWED;
            }
            
        }
    }
}
